<docs>
  ## 编辑求职意向
</docs>
<template>
  <div class="wrap">
    <my-bread title="求职意向"></my-bread>
    <co-form :model="data" :rules="rules" ref="form">
      <co-position
        label="求职岗位"
        v-model="data.scids"
        :arrList=gwList
        :deleteList=deleteList
        ref="qzgw"
      ></co-position>
      <co-select
        prop="ygxs"
        label="用工形式"
        disabled
        v-model="data.ygxs"
        :list="codeTable.zyjs_d_dwygxs"
      ></co-select>
      <co-select
        v-show="xclxFlag"
        label="薪酬类型"
        v-model="data.xclx"
        :list="xclx"
      ></co-select>
      <co-input prop="zdnx" v-if="nx" label="最低年薪" v-model="data.zdnx" placeholder="请输入最低年薪"></co-input>
      <co-input
        prop="zgnx"
        v-if="nx"
        label="最高年薪"
        type="tel"
        v-model="data.zgnx"
        placeholder="请输入最高年薪"
      ></co-input>
      <co-input prop="zdyx" v-if="yx" label="最低月薪" v-model="data.zdyx" placeholder="请输入最低月薪"></co-input>
      <co-input
        prop="zgyx"
        v-if="yx"
        label="最高月薪"
        type="tel"
        v-model="data.zgyx"
        placeholder="请输入最高月薪"
      ></co-input>
       <co-input prop="zdrx" v-if="rx" label="最低日薪" v-model="data.zdrx" placeholder="请输入最低日薪"></co-input>
      <co-input
        prop="zgrx"
        v-if="rx"
        label="最高日薪"
        v-model="data.zgrx"
        placeholder="请输入最高日薪"
      ></co-input>
      <!-- <co-select label="月薪范围" v-if="yx" :list="codeTable.zyjs_d_qwxcqj" prop="yxfw" v-model="data.yxfw"></co-select>
      <co-select label="时薪范围" v-if="sx" :list="codeTable.zyjs_d_qwxcqj" prop="sxfw" v-model="data.sxfw"></co-select> -->
      <co-input prop="zdsx" v-if="sx" label="最低时薪" v-model="data.zdsx" placeholder="请输入最低时薪"></co-input>
      <co-input
        prop="zgsx"
        v-if="sx"
        label="最高时薪"
        type="tel"
        v-model="data.zgsx"
        placeholder="请输入最高时薪"
      ></co-input>
      <co-input prop="ycxlwf" v-if="ycxlwf" label="一次性劳务费" v-model="data.ycxlwf" placeholder="请输入一次性劳务费"></co-input>
      <co-select label="工作地区" :list="codeTable.zyjs_d_gzdq" prop="qwjydq" v-model="data.qwjydq"></co-select>
    </co-form>
    <div class="btn-wrap">
      <button class="weui-btn weui-btn_primary" v-if="nextFlag" @click="save" type="button">保存</button>
      <button class="weui-btn weui-btn_primary" v-else @click="save(1)" type="button">下一步</button>
    </div>
  </div>
</template>
<script>
import coForm from "base/form/form";
import coInput from "base/form/input";
import coSelect from "base/form/select";
import { validator } from "common/js/valid";
import coPosition from "base/form/position";
// import coPosition from "base/form/searchinput";

export default {
  name: "editJobIntent",
  components: {
    coForm,
    coInput,
    coSelect,
    coPosition
  },
  data() {
    return {
      dele: false,
      nextFlag: true,
      deleteList:[],
      gwList: [],
      cymujk: "", //常用模糊接口
      data: {
        qzyxids: [], // 求职意向id
        grqzid: "", // 个人求职id
        qwqyxz: "", // 企业性质
        qwcshy: "", // 单位行业
        qwjydq: "", // 工作地区
        qwjydd: "", // 工作地点
        ygxs: "", // 用工形式
        gwmcs: [], // 岗位名称
        gwbms: [], // 岗位编码
        yxfw: "", // 月薪范围
        sxfw: "", // 时薪范围
        ywcz: ""
      },
      rules: {
        // gwmc: validator("64,least,岗位名称,true"),
        gwbm: validator("64,least,求职岗位,false"), // 岗位名称
        qwcshy: validator('5,"full","单位行业",true'), // 单位行业
        qwjydq: validator('12,"full","工作地区",false'), // 工作地区
        qwjydd: validator('128,"full","工作地点",true'), // 工作地点
        ygxs: validator('2,"full","用工形式",false'), // 用工形式
        // xclx: validator('2,"full","薪酬类型",true'), // 薪酬类型
        // yxfw: validator('6,"full","月薪范围",true'), // 月薪范围
        // sxfw: validator('6,"full","时薪范围",true'), // 时薪范围
        zdnx: validator('7,"number","最低年薪",true', (rules, value, cb) => {
          const { bjszdyx } = this*12;
          if (!value && !this.data.zgnx) {
            cb(new Error("最低与最高年薪不能都为空"));
          } else if (+value < bjszdyx) {
            cb(new Error(`最低年薪不能低于北京市最低工资${bjszdyx}`));
          } else {
            cb();
          }
        }),
        zgnx: validator('7,"number","最高年薪",true', (rules, value, cb) => {
          const { bjszdyx } = this*12;
          if (!value && !this.data.zdnx) {
            cb(new Error("最低与最高年薪不能都为空"));
          } else {
            cb();
          }
        }),
        ycxlwf: validator('7,"number","一次性劳务费",true'),
        // 期望最高薪资
        zdyx: validator('7,"number","最低月薪",true', (rules, value, cb) => {
          const { bjszdyx } = this;
          if (!value && !this.data.zgyx) {
            cb(new Error("最低与最高月薪不能都为空"));
          } else if (+value < bjszdyx) {
            cb(new Error(`最低月薪不能低于北京市最低工资${bjszdyx}`));
          } else {
            cb();
          }
        }),
        // 期望最低薪资
        zgyx: validator('7,"number","最高月薪",true', (rules, value, cb) => {
          if (!value && !this.data.zdyx) {
            cb(new Error("最低与最高月薪不能都为空"));
          } else {
            cb();
          }
        }), // 期望最高月薪

   
         zgrx: validator('7,"number","最高日薪",true', (rules, value, cb) => {
          if (!value && !this.data.zdrx) {
            cb(new Error("最低与最高日薪不能都为空"));
          } else {
            cb();
          }
        }), // 最高日薪

         zdrx: validator('7,"number","最低日薪",true', (rules, value, cb) => {
          if (!value && !this.data.zgrx) {
            cb(new Error("最低与最高日薪不能都为空"));
          } else {
            cb();
          }
        }),// 最低日薪

        zdsx: validator('7,"number","最低时薪",true', (rules, value, cb) => {
          if (!value && !this.data.zgsx) {
            cb(new Error("最低与最高时薪不能都为空"));
          } else {
            cb();
          }
        }), // 最低时薪
        zgsx: validator('7,"number","最高时薪",true', (rules, value, cb) => {
          if (!value && !this.data.zdsx) {
            cb(new Error("最低与最高时薪不能都为空"));
          } else {
            cb();
          }
        }), // 最高时薪
        qwdjzclx: validator('3,"full","期望登记注册类型",false'), // 期望登记注册类型
        qtdjzclx: validator('3,"full","其他登记注册类型",false') // 其他登记注册类型
      },
      codeTable: {
        zyjs_d_qwxcqj:[], //薪酬范围
        zyjs_d_dwygxs:[], // 用工形式
        zyjs_d_gzdq:[], // 工作地区
        // cdl_orgtype: [], // 单位性质
        // cdg_regtype: [], // 期望登记注册类型
        // cdl_orgtype_01: [], // 其他登记注册类型
        // cdg_industry_all: [] // 单位行业
      },
      bjszdyx: "", // 北京市最底薪资
      gzdq_xs: "",
      qwdjzclx_xs: "",
      qwcshy_xs: "",
      visible: false,
      visibleSuggestion: false,
      qtzclx: false,
      zclx: false,
      nx: false,
      yx: false,
      sx: false,
      rx:false,
      ycxlwf: false,
      // xclx: [{ dmid: "01", dmmc: "年薪" },{ dmid: "02", dmmc: "月薪" }],
      xclx: [],
      ygxs:"",
      xclxFlag: false,//全职显示年薪，月薪
      obj: {
        grqzid: "",
        qzyxids: [],
        ywcz: "1" //业务操作 1新增； 2修改
      }
    };
  },
  watch: {
    "data.ygxs": function watcher(val) {
      this.$nextTick(_=>{
        if (val == '40') {
          this.sx = true;
          return
        }
        if (this.ygxs !== val) {
          this.data.xclx = "";
        }
      })
      this.ycxlwf = false;
      this.xclxFlag = false;
      this.sx = false;
      this.yx = false;
      this.nx = false;
      this.rx = false;
      if(!val) return
      if(val == '10'){
        this.xclx= [{ dmid: "01", dmmc: "年薪" },{ dmid: "02", dmmc: "月薪" }];
        this.xclxFlag = true;
      }else if (val === "40") {
        this.sx = true;
      } else {
        this.xclx= [{ dmid: "02", dmmc: "月薪" },{ dmid: "06", dmmc: "日薪" },{ dmid: "03", dmmc: "时薪" },{ dmid: "04", dmmc: "一次性劳务费" }];
        this.xclxFlag = true;
        this.ycxlwf = false;
      }
    },
    "data.xclx": function (val) {
      if(!val){
        this.ycxlwf = false;
        this.yx = false;
        this.sx = false;
        this.nx = false;
          this.rx = false;
      }else if(val == '01'){
        this.nx = true;
        this.yx = false;
        this.sx = false;
        this.ycxlwf = false;
          this.rx = false;
      }else if(val == '02'){
        this.yx = true;
        this.sx = false;
        this.nx = false;
        this.ycxlwf = false;
          this.rx = false;
      } else if(val == '03'){
        this.sx = true;
        this.yx = false;
        this.nx = false;
        this.ycxlwf = false;
          this.rx = false;
      } else if(val == '04'){
        this.yx = false;
        this.nx = false;
        this.sx = false;
        this.ycxlwf = true;
         this.rx = false;
      }
       else if(val == '06'){
        this.yx = false;
        this.nx = false;
        this.sx = false;
        this.ycxlwf = false;
        this.rx = true;
      }
    }
  },
  methods: {
    /*  查询求职意向信息 */
    GET_getInfo() {
      var _this = this;
      this.$loading = true;
      this.$http
        .get("/grgl/grxqCx")
        .then(res => {
          const resData = res.returnData;
          this.data = resData.qzyx;
          this.ygxs = this.data.ygxs;
          this.nextFlag = resData.sfyjbdj=='0'?false:true;
          this.obj.grqzid = resData.jbxx.grqzid;
          this.deleteList = resData.qzyx.qzyxids;
          //判断新增修改  数组长度0  新增
          if (resData.qzyx.gwbms.length == 0) {
            this.data.ywcz = "1";
            // this.gwList=[];
          } else {
            var arr = [];
            resData.qzyx.gwbms.map((item, i) => {
              return arr.push({ gwbm: item, gwmc: resData.qzyx.gwmcs[i] });
            });
            this.gwList = arr;
            this.data.ywcz = "2";
          }
        })
        .finally(() => {
          this.$loading = false;
        });
    },
    /* 获取代码表 */
    GET_codeTable() {
      const arrTableName = Object.keys(this.codeTable);
      this.$http
        .get("/dmbgl/dmblbCx", {
          params: {
            table_name: arrTableName.join()
          }
        })
        .then(res => {
          this.getCodeTabled = true;
          const data = res.returnData.dmblb;
          arrTableName.forEach(item => {
            this.codeTable[item] = data[item];
          });
        });
    },
    save() {
      this.$refs.form.validate(() => {
        if (this.gwList.length== 0) {
          this.$refs.form.errorMsg = '求职岗位不能为空！';
          return;
        }
        if ((this.data.ygxs== '10' || this.data.ygxs== '20'|| this.data.ygxs== '30') && !this.data.xclx) {
          this.$refs.form.errorMsg = '薪酬类型不能为空！';
          return;
        }
        if (this.data.xclx == '01') {
          this.data.zdyx = this.data.zgyx = this.data.zgsx = this.data.zdsx =this.data.zgrx = this.data.zdrx = this.data.ycxlwf ='';
        } else if (this.data.xclx == '02'){
          this.data.zdnx = this.data.zgnx = this.data.zgsx = this.data.zdsx =this.data.zgrx = this.data.zdrx = this.data.ycxlwf ='';
        } else if (this.data.xclx == '03'){
          this.data.zdnx = this.data.zgnx = this.data.zgyx = this.data.zdyx =this.data.zgrx = this.data.zdrx = this.data.ycxlwf ='';
        }else {// 日薪的时候
          this.data.zdnx = this.data.zgnx = this.data.zgyx = this.data.zdyx =this.data.zgsx = this.data.zdsx ='';
        }
        var gwbm = [],
          gwmc = [];
        this.gwList.map((item, n) => {
          // return gwbm.push(item.gwbm), gwmc.push(this.$refs.qzgw[n].value);
          return gwbm.push(item.gwbm), gwmc.push(item.gwmc);
        });
        this.data.gwmcs = gwmc;
        this.data.gwbms = gwbm;
        this.$loading = true;
            this.$http
              .post("/grgl/qzyxBc", this.data)
              .then(res => {
                const resData = res.returnData;
                this.$alert(resData.message, () => {
                  const code = +resData.executeResult;
                  this.$store.state.userInfo.sfyqzdj = '1';
                  if (code && !this.nextFlag) {
                    this.$router.push({ name: "UserResumeBaseInfo" });
                  } else if (code) {
                    this.$router.push({ name: "userResume" });
                  }
                });
              })
              .finally(() => {
                this.$loading = false;
              });
      });
    },
    // 添加岗位
    // add() {
    //   if (this.gwList[this.gwList.length-1].gwmc== '') {
    //     this.$alert("填写求职岗位后再添加岗位");
    //     return;
    //   }
    //   if (this.gwList.length == 3) {
    //     this.$alert("最多新增三个岗位");
    //     return;
    //   }
    //   this.gwList.push({ gwmc: "", gwbm: "" });
    // },
    // 删除岗位
    // async deleteData(n) {
    //   if (!this.gwList[n].gwbm ) {
    //     this.gwList.splice(n, 1);
    //   }else{
    //     try {
    //       await this.$confirm('是否删除该条求职意向？', '提示');
    //       const res = await this.$http.post('/grgl/qzyxBc', {
    //         qzyxid: this.data.qzyxids[n]?this.data.qzyxids[n]:'',
    //         grqzid: this.obj.grqzid,
    //         ywcz: 0
    //       });
    //       this.$alert(res.returnData.message);
    //       if (res.returnData.executeResult === '1') {
    //         this.gwList.splice(n, 1);
    //       }
    //     } catch (e) {
    //       //
    //     }
    //   }
    // },
  },
  created() {
    //求职意向查询
    this.GET_getInfo();
    // 获取代码表
    this.getCodeTabled = false;
    this.GET_codeTable();
    // 隐藏home按钮
    this.$store.commit("SET_VISIBLE_ALL", false);
  }
};
</script>
<style scoped lang="scss">
@import "~common/scss/var.scss";
.wrap {
  .btn-wrap {
    display: flex;
    .weui-btn {
      margin: 0 auto;
      flex: 0 1 60%;
      margin-top: $margin-base;
    }
  }
  /deep/ .weui-cell__ft {
    padding-right: $padding-btn * 5;
  }
}

.btnDisabled {
  opacity: 0.5;
  pointer-events: none;
}
.btnDisabled:before {
  content: " ";
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  height: 1px;
  border-top: 1px solid #ccc;
  color: #e5e5e5;
  -webkit-transform-origin: 0 0;
  transform-origin: 0 0;
  -webkit-transform: scaleY(0.5);
  transform: scaleY(0.5);
  left: 30px;
  z-index: 2;
}
.gwPosion {
  position: relative;
  i {
    position: absolute;
    right: $font-size-large * 2;
    top: $margin-top * 2;
    color: red;
    font-size: $font-size-small;
  }
}
</style>

